#include <iostream>
#include "Point.h"
   
#include <limits>
#include <stddef.h>
#include "boost/numeric/interval.hpp"

#include <vector>

#include <math.h>
#include <stdlib.h>
#include <cstdio>
#include <cstdlib>
#include <string.h>
#include <float.h>

static const double EPS  = std::numeric_limits<double>::epsilon();

int simple_turn(const Point& a, const Point& b, const Point& c) {
        double turn = (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
        double eps = 4 * EPS * (abs((b.x - a.x) * (c.y - a.y)) + abs((b.y - a.y) * (c.x - a.x)));
        if (turn > eps)
            return 1;
		if (turn < -eps)
			return -1;
        return 0;
}

typedef boost::numeric::interval<double> interval;

Point operator -(Point a, Point b)
{
        return Point(a.x - b.x, a.y - b.y);
}

int interval_turn(Point a, Point b, Point c)
{
        interval h[6];
        h[0] = interval(b.x) * interval(c.y);
        h[1] = interval(b.y) * interval(c.x);
        h[2] = interval(a.y) * interval(c.x);
        h[3] = interval(a.x) * interval(c.y);
        h[4] = interval(a.x) * interval(b.y);
        h[5] = interval(a.y) * interval(b.x);

        interval res = h[0] - h[1] + h[2] - h[3] + h[4] - h[5];
        if (res.lower() > 0) {
            return 1;
        }
        if (res.upper() < 0) {
              return -1;
        }        
        return 0;
}

double sum(double a, double b, double &r)
{
	double res = a + b;
	double bv = res - a;
	double av = res - bv;
	r = (a - av) + (b - bv);
	return res;
}
    
void split(double a, double &ah, double &al)
{
    int s = std::numeric_limits<double>::digits - std::numeric_limits<double>::digits / 2;
    double c = ((1LL << s) + 1LL) * a;
    ah = c - (c - a);
    al = a - ah;
}

double mul(double a, double b, double &y)
{
    double x = a * b;
    double ah, al, bh, bl;
    split(a, ah, al);
    split(b, bh, bl);
    y = (al * bl) - (((x - (ah * bh)) - (al * bh)) - (bl * ah));
    return x;
}

    
template <int N>
void grow_expansion(double *e, double b, double *h)
{
    double q = b;
    for (int i = 0; i < N; i++)
    {
        q = sum(e[i], q, h[i]);
    }
    h[N] = q;
}

template <int N1, int N2>
void expansion_sum(double *e, double *f)
{
    for(int i = 0; i < N2; i++)
    {
        grow_expansion<N1>(e + i, f[i], e + i);
    }
}

int adaptive_turn(const Point &a, const Point &b, const Point &c)
{
    double p[12];
    
    p[0] = mul(b.x, c.y, p[1]);
    p[2] = mul(-b.x, a.y, p[3]);
    p[4] = mul(-a.x, c.y, p[5]);
    p[6] = mul(-b.y, c.x, p[7]);
    p[8] = mul(b.y, a.x, p[9]);
    p[10] = mul(a.y, c.x, p[11]);

    expansion_sum<2, 2>(p, p + 2);
    expansion_sum<2, 2>(p + 4, p + 6);
    expansion_sum<2, 2>(p + 8, p + 10);
    expansion_sum<4, 4>(p, p + 4);
    expansion_sum<8, 4>(p, p + 8);
    
    for (int i = 11; i >= 0; i--)
    {
        if (p[i] > 0)
            return 1;
        if (p[i] < 0)
            return -1;
    }
    return 0;
}



int full_turn(const Point& a, const Point& b, const Point& c) {
    int simple = simple_turn(a, b, c);
	if (simple != 0) { 
		return simple;
    } else {
		int inter = interval_turn(a, b, c);
		if (inter != 0){
			return inter;
		} else {
			return adaptive_turn(a, b, c);
		}
    }
}

bool out_of_box(Point a, Point b, Point c, Point d) 
{
	return ((a.x > c.x && a.x > d.x && b.x > c.x && b.x > d.x) ||
                (a.x < c.x && a.x < d.x && b.x < c.x && b.x < d.x))
                ||
                ((a.y > c.y && a.y > d.y && b.y > c.y && b.y > d.y) ||
                (a.y < c.y && a.y < d.y && b.y < c.y && b.y < d.y));
}

bool intersection(Point a, Point b, Point c, Point d)
{
	if(out_of_box(a, b, c, d))
			return false;

	int t1 = full_turn(a, b, c);
	int t2 = full_turn(a, b, d);
	int t3 = full_turn(c, d, a);
	int t4 = full_turn(c, d, b);
	if ((t1 == 0) && (t2 == 0) || (t3 == 0) && (t4 == 0)) {
		double minx = std::min(c.x, d.x),
		miny = std::min(c.y, d.y),
		maxx = std::max(c.x, d.x),
		maxy = std::max(c.y, d.y);
		if (a.x >= minx && a.x <= maxx && a.y >= miny && a.y <= maxy)
			return true;
		else
			return false;
	}
	return (t1 * t2 <= 0) && (t3 * t4 <= 0);
}

class Random
{
private:
    int cern;

    static const int a = 535322;
    static const int b = 101204943;
	static const int mask = 0x7fffffff;
public:
    Random(int cern_)
    { 
		cern = cern_;
	}

    int next_int()
    {
        return (cern = cern * a + b) & mask;
    }

    double next_double()
    {
        return (-1000 + 2000 * 1.0 / (1 << 30) * next_int());
    }
};

int get_result(std::vector<bool> const& intersects)
{
    int res = 0;
    for (int i = 0, p = 1; i < intersects.size(); i++, p *= 2) 
	{
        if (intersects[i])
            res += p;
    }
    return res;
}

int main(){
    using std::cin;
    using std::cout;
    int n = 100, t = 1, cern = 0;

    cin >> n >> t;
    Random rand(0);

	if (t == 1)
    {
        cin >> cern;
        rand = Random(cern);
    }
   
    std::vector<bool> intersects(n);
    for (int i = 0; i < n; i++)
    {
        Point p[4];
        if (cern == 0)
            cin >> p[0].x >> p[0].y >> p[1].x >> p[1].y >> p[2].x >> p[2].y >> p[3].x >> p[3].y;
        else 
        {
			p[0].x = rand.next_double();
			p[0].y = rand.next_double();
			p[1].x = rand.next_double();
			p[1].y = rand.next_double();
			p[2].x = rand.next_double();
			p[2].y = rand.next_double();            
			p[3].x = rand.next_double();
			p[3].y = rand.next_double();
		}
        
        intersects[i] = (intersection(p[0], p[1], p[2], p[3]));
	}

	std::cout << get_result(intersects); 
}